//
//  WXEmotionButton.swift
//  weibo
//
//  Created by 王旭 on 16/4/29.
//  Copyright © 2016年 王旭. All rights reserved.
//

import UIKit

class WXEmotionButton: UIButton {

    var emotion : WXEmotionModel? {
        didSet{
            
            //判断是否为空
            guard let _ = emotion else {
                return
            }
            
            if emotion?.type == "1" {
                self.setImage(nil, forState: .Normal)
                self.setTitle((emotion!.code! as NSString).emoji(), forState: .Normal)
            }else{
                //设置图片
                let image = UIImage(named: "\(emotion!.folderName ?? "")/\(emotion!.png ?? "")", inBundle: WXEmotionViewModel.sharedEmotionViewModel.emotionBundel, compatibleWithTraitCollection: nil)
                self.setImage(image, forState: .Normal)
                self.setTitle(nil, forState: .Normal)
            }

        }
    }

}
